package com.yunwaikeji.gy_tool_library.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.yunwaikeji.gy_tool_library.R;
import com.yunwaikeji.gy_tool_library.info.GYTopBarInfo;
import com.yunwaikeji.gy_tool_library.utils.display.GYDisplayUtils;
import com.yunwaikeji.gy_tool_library.utils.GYViewUtils;
import com.yunwaikeji.gy_tool_library.utils.GYStatusBarUtils;
import com.yunwaikeji.gy_tool_library.view.GYImageView;
import com.yunwaikeji.gy_tool_library.view.GYLinearLayout;
import com.yunwaikeji.gy_tool_library.view.GYRelativeLayout;
import com.yunwaikeji.gy_tool_library.view.GYTextView;

import java.util.List;

public class GYTopBar extends GYLinearLayout implements GYTopBarInfo {
    //==============================================================================================
    //工具
    private void setImageViewSizePx(GYImageView gyImageView, Drawable drawable, int widthPx, int heightPx) {
        int width;
        int height;
        if (drawable != null && widthPx < 0) {
            width = drawable.getIntrinsicWidth();
        } else {
            width = widthPx;
        }
        if (drawable != null && heightPx < 0) {
            height = drawable.getIntrinsicHeight();
        } else {
            height = heightPx;
        }
        LayoutParams layoutParams = (LayoutParams) gyImageView.getLayoutParams();
        layoutParams.width = width;
        layoutParams.height = height;
        gyImageView.setLayoutParams(layoutParams);
    }

    //==============================================================================================
    //顶部
    public GYTopBar setTopShow(boolean topShow) {
        this.topShow = topShow;
        topView.setVisibility(topShow ? VISIBLE : GONE);
        return this;
    }

    public boolean isTopShow() {
        return topShow;
    }

    public GYTopBar setTopBackgroundColor(int topBackgroundColor) {
        this.topBackgroundColor = topBackgroundColor;
        topView.setBackgroundColor(topBackgroundColor);
        return this;
    }

    public int getTopBackgroundColor() {
        return topBackgroundColor;
    }

    public GYTopBar setTopHeightPx(int topHeightPx) {
        this.topHeightPx = normalInt(topHeightPx, GYStatusBarUtils.getHeight(getContext()));
        topView.setLayoutParams(new LayoutParams(MATCH_PARENT, topHeightPx));
        return this;
    }

    public GYTopBar setTopHeightDp(int topHeightDp) {
        setTopHeightPx(GYDisplayUtils.dp2px(getContext(), topHeightDp));
        return this;
    }

    public int getTopHeightPx() {
        return topHeightPx;
    }

    //==============================================================================================
    //中间
    public GYTopBar setCenterBackgroundColor(int color) {
        this.centerBackgroundColor = normalInt(color, Color.TRANSPARENT);
        centerView.setBackgroundColor(centerBackgroundColor);
        return this;
    }

    public int getCenterBackgroundColor() {
        return centerBackgroundColor;
    }

    public GYTopBar setCenterHeightPx(int centerHeightPx) {
        this.centerHeightPx = normalInt(centerHeightPx, GYDisplayUtils.dp2px(getContext(), 45));
        centerView.setLayoutParams(new LayoutParams(MATCH_PARENT, this.centerHeightPx));
        return this;
    }

    public GYTopBar setCenterHeightDp(int bottomHeightDp) {
        return setCenterHeightPx(GYDisplayUtils.dp2px(getContext(), bottomHeightDp));
    }

    public int getCenterHeightPx() {
        return centerHeightPx;
    }

    //==============================================================================================
    //底部
    public GYTopBar setBottomLineColor(int bottomLineColor) {
        this.bottomLineColor = bottomLineColor;
        bottomLineView.setBackgroundColor(bottomLineColor);
        return this;
    }

    public int getBottomLineColor() {
        return bottomLineColor;
    }

    public GYTopBar setBottomLineHeightDp(int bottomLineDp) {
        return setBottomLineHeightPx(GYDisplayUtils.dp2px(getContext(), bottomLineDp));
    }

    public GYTopBar setBottomLineHeightPx(int bottomLineHeightPx) {
        this.bottomLineHeightPx = bottomLineHeightPx;
        bottomLineView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, bottomLineHeightPx));
        return this;
    }

    public int getBottomLineHeightPx() {
        return bottomLineHeightPx;
    }

    public GYTopBar setBottomLineShow(boolean bottomLineShow) {
        this.bottomLineShow = bottomLineShow;
        bottomLineView.setVisibility(bottomLineShow ? VISIBLE : GONE);
        return this;
    }

    public boolean isBottomLineShow() {
        return bottomLineShow;
    }

    //==============================================================================================
    //中间左边
    public GYTopBar setLeftPaddingLeftPx(int leftPaddingLeftPx) {
        this.leftPaddingLeftPx = leftPaddingLeftPx;
        leftLL.setPadding(leftPaddingLeftPx, 0, 0, 0);
        return this;
    }

    public GYTopBar setLeftPaddingLeftDp(int leftPaddingLeftDp) {
        return setLeftPaddingLeftPx(GYDisplayUtils.dp2px(getContext(), leftPaddingLeftDp));
    }

    public int getLeftPaddingLeftPx() {
        return leftPaddingLeftPx;
    }

    public GYTopBar setLeftSpacingPx(int leftSpacingPx) {
        leftImageView.getViewSet().setMarginPx(0, 0, leftSpacingPx, 0);
        return this;
    }

    public GYTopBar setLeftSpacingDp(int leftSpacingDp) {
        return setLeftSpacingPx(GYDisplayUtils.dp2px(getContext(), leftSpacingDp));
    }

    //==============================================================================================
    //中间中间
    public GYTopBar setTitleLeftSpacingPx(int titleLeftSpacingPx) {
        titleLeftImageView.getViewSet().setMarginPx(0, 0, titleLeftSpacingPx, 0);
        return this;
    }

    public GYTopBar setTitleLeftSpacingDp(int titleLeftSpacingDp) {
        return setTitleLeftSpacingPx(GYDisplayUtils.dp2px(getContext(), titleLeftSpacingDp));
    }

    public GYTopBar setTitleRightSpacingPx(int titleRightSpacingPx) {
        titleRightImageView.getViewSet().setMarginPx(titleRightSpacingPx, 0, 0, 0);
        return this;
    }

    public GYTopBar setTitleRightSpacingDp(int titleRightSpacingDp) {
        return setTitleRightSpacingPx(GYDisplayUtils.dp2px(getContext(), titleRightSpacingDp));
    }

    //==============================================================================================
    //中间右边
    public GYTopBar setRightPaddingRightPx(int rightPaddingRightPx) {
        this.rightPaddingRightPx = rightPaddingRightPx;
        rightLL.setPadding(0, 0, rightPaddingRightPx, 0);
        return this;
    }

    public GYTopBar setRightPaddingRightDp(int rightDp) {
        return setRightPaddingRightPx(GYDisplayUtils.dp2px(getContext(), rightDp));
    }

    public int getRightPaddingRightPx() {
        return rightPaddingRightPx;
    }

    public GYTopBar setRightSpacingPx(int rightSpacingPx) {
        rightTextView.getViewSet().setMarginPx(rightSpacingPx, 0, 0, 0);
        return this;
    }

    public GYTopBar setRightSpacingDp(int rightSpacingDp) {
        return setLeftSpacingPx(GYDisplayUtils.dp2px(getContext(), rightSpacingDp));
    }

    public GYTopBar setRightSpacing1Px(int rightSpacing1Px) {
        rightImageView.getViewSet().setMarginPx(rightSpacing1Px, 0, 0, 0);
        return this;
    }

    public GYTopBar setRightSpacing1Dp(int rightSpacing1Dp) {
        return setLeftSpacingPx(GYDisplayUtils.dp2px(getContext(), rightSpacing1Dp));
    }

    //==============================================================================================
    //中间左边图片
    public GYTopBar setLeftDrawable(Drawable leftDrawable) {
        this.leftDrawable = leftDrawable;
        if (leftDrawable == null) {
            leftImageView.setVisibility(GONE);
        } else {
            leftImageView.getViewSet().setVisibility(VISIBLE).toView()
                    .getImageBuilder()
                    .setImageDrawable(leftDrawable).build();
        }
        return this;
    }

    public GYTopBar setLeftDrawable(int resId) {
        return setLeftDrawable(getResources().getDrawable(resId));
    }

    public Drawable getLeftDrawable() {
        return leftDrawable;
    }

    public GYTopBar setLeftDrawableWidthDp(int leftDrawableWidthDp) {
        return setLeftDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), leftDrawableWidthDp));
    }

    public GYTopBar setLeftDrawableWidthPx(int leftDrawableWidthPx) {
        return setLeftDrawableSizePx(leftDrawableWidthPx, leftDrawableHeightPx);
    }

    public GYTopBar setLeftDrawableHeightDp(int leftDrawableHeightDp) {
        return setLeftDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), leftDrawableHeightDp));
    }

    public GYTopBar setLeftDrawableHeightPx(int leftDrawableHeightPx) {
        return setLeftDrawableSizePx(leftDrawableWidthPx, leftDrawableHeightPx);
    }

    public GYTopBar setLeftDrawableSizePx(int leftDrawableWidthPx, int leftDrawableHeightPx) {
        this.leftDrawableWidthPx = leftDrawableWidthPx;
        this.leftDrawableHeightPx = leftDrawableHeightPx;
        setImageViewSizePx(leftImageView, leftDrawable, leftDrawableWidthPx, leftDrawableHeightPx);
        return this;
    }

    public int getLeftDrawableWidthPx() {
        return leftDrawableWidthPx;
    }

    public int getLeftDrawableHeightPx() {
        return leftDrawableHeightPx;
    }

    public GYImageView getLeftImageView() {
        return leftImageView;
    }

    public GYTopBar setLeftImageViewMarginPx(int leftPx, int rightPx) {
        leftImageView.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setLeftImageViewMarginDp(int leftDp, int rightDp) {
        leftImageView.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    //==============================================================================================
    //中间左边文字
    public GYTopBar setLeftText(String text) {
        if (TextUtils.isEmpty(text)) {
            leftTextView.setVisibility(GONE);
        } else {
            leftTextView.getViewSet().setVisibility(VISIBLE)
                    .setText(text);
        }
        return this;
    }

    public String getLeftTextString() {
        return leftTextView.getViewSet().getTextString();
    }

    public GYTopBar setLeftTextSizePx(int sizePx) {
        leftTextSizePx = sizePx;
        leftTextView.getViewSet().setTextSizePx(leftTextSizePx);
        return this;
    }

    public int getLeftTextSizePx() {
        return leftTextSizePx;
    }

    public GYTopBar setLeftTextSizeSp(int sizeSp) {
        return setLeftTextSizePx(GYDisplayUtils.sp2px(getContext(), sizeSp));
    }

    public GYTopBar setLeftTextColor(int color) {
        leftTextColor = color;
        leftTextView.getViewSet().setTextColor(leftTextColor);
        return this;
    }

    public int getLeftTextColor() {
        return leftTextColor;
    }

    public GYTopBar setLeftTextViewMarginPx(int leftPx, int rightPx) {
        leftTextView.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setLeftTextViewMarginDp(int leftDp, int rightDp) {
        leftTextView.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    public GYTextView getLeftTextView() {
        return leftTextView;
    }

    public GYTopBar setLeftTextBold(boolean bold) {
        leftTextView.getViewSet().setBold(bold);
        return this;
    }

    public boolean isLeftTextBold() {
        return leftTextView.getViewSet().isBold();
    }

    //==============================================================================================
    //中间标题左边图片
    public GYTopBar setTitleLeftDrawable(Drawable titleLeftDrawable) {
        this.titleLeftDrawable = titleLeftDrawable;
        if (titleLeftDrawable == null) {
            titleLeftImageView.setVisibility(GONE);
        } else {
            titleLeftImageView.getViewSet().setVisibility(VISIBLE)
                    .toView()
                    .getImageBuilder()
                    .setImageDrawable(titleLeftDrawable).build();
        }
        return this;
    }

    public GYTopBar setTitleLeftDrawable(int resId) {
        return setTitleLeftDrawable(getResources().getDrawable(resId));
    }

    public Drawable getTitleLeftDrawable() {
        return titleLeftDrawable;
    }

    public GYTopBar setTitleLeftDrawableWidthDp(int titleLeftDrawableWidthDp) {
        return setTitleLeftDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), titleLeftDrawableWidthDp));
    }

    public GYTopBar setTitleLeftDrawableWidthPx(int titleLeftDrawableWidthPx) {
        return setTitleLeftDrawableSizePx(titleLeftDrawableWidthPx, titleLeftDrawableHeightPx);
    }

    public GYTopBar setTitleLeftDrawableHeightDp(int titleLeftDrawableHeightDp) {
        return setTitleLeftDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), titleLeftDrawableHeightDp));
    }

    public GYTopBar setTitleLeftDrawableHeightPx(int titleLeftDrawableHeightPx) {
        return setTitleLeftDrawableSizePx(titleLeftDrawableWidthPx, titleLeftDrawableHeightPx);
    }

    public GYTopBar setTitleLeftDrawableSizePx(int titleLeftDrawableWidthPx, int titleLeftDrawableHeightPx) {
        this.titleLeftDrawableWidthPx = titleLeftDrawableWidthPx;
        this.titleLeftDrawableHeightPx = titleLeftDrawableHeightPx;
        setImageViewSizePx(titleLeftImageView, titleLeftDrawable, titleLeftDrawableWidthPx, titleLeftDrawableHeightPx);
        return this;
    }

    public GYTopBar setTitleLeftDrawableSizeDp(int titleLeftDrawableWidthDp, int titleLeftDrawableHeightDp) {
        return setTitleLeftDrawableSizePx(GYDisplayUtils.dp2px(getContext(), titleLeftDrawableWidthDp), GYDisplayUtils.dp2px(getContext(), titleLeftDrawableHeightDp));
    }

    public int getTitleLeftDrawableWidthPx() {
        return titleLeftDrawableWidthPx;
    }

    public int getTitleLeftDrawableHeightPx() {
        return titleLeftDrawableHeightPx;
    }

    public GYImageView getTitleLeftImageView() {
        return titleLeftImageView;
    }

    public GYTopBar setTitleLeftImageViewMarginPx(int leftPx, int rightPx) {
        titleLeftImageView.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setTitleLeftImageViewMarginDp(int leftDp, int rightDp) {
        titleLeftImageView.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    //==============================================================================================
    //中间标题文字
    public GYTopBar setTitleText(String text) {
        if (TextUtils.isEmpty(text)) {
            titleTextView.setVisibility(GONE);
        } else {
            titleTextView.getViewSet().setVisibility(VISIBLE)
                    .setText(text);
        }
        return this;
    }

    public String getTitleTextString() {
        return titleTextView.getViewSet().getTextString();
    }

    public GYTopBar setTitleTextSizePx(int sizePx) {
        titleTextSizePx = sizePx;
        titleTextView.getViewSet().setTextSizePx(titleTextSizePx);
        return this;
    }

    public int getTitleTextSizePx() {
        return titleTextSizePx;
    }

    public GYTopBar setTitleTextSizeSp(int sizeSp) {
        return setTitleTextSizePx(GYDisplayUtils.sp2px(getContext(), sizeSp));
    }

    public GYTopBar setTitleTextColor(int color) {
        titleTextColor = color;
        titleTextView.getViewSet().setTextColor(titleTextColor);
        return this;
    }

    public int getTitleTextColor() {
        return titleTextColor;
    }

    public GYTopBar setTitleTextViewMarginPx(int leftPx, int rightPx) {
        titleTextView.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setTitleTextViewMarginDp(int leftDp, int rightDp) {
        titleTextView.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    public GYTextView getTitleTextView() {
        return titleTextView;
    }

    public GYTopBar setTitleTextBold(boolean bold) {
        titleTextView.getViewSet().setBold(bold);
        return this;
    }

    public boolean isTitleTextBold() {
        return titleTextView.getViewSet().isBold();
    }

    //==============================================================================================
    //中间标题右边图片
    public GYTopBar setTitleRightDrawable(Drawable titleRightDrawable) {
        this.titleRightDrawable = titleRightDrawable;
        if (titleRightDrawable == null) {
            titleRightImageView.setVisibility(GONE);
        } else {
            titleRightImageView.getViewSet().setVisibility(VISIBLE).toView()
                    .getImageBuilder()
                    .setImageDrawable(titleRightDrawable).build();
        }
        return this;
    }

    public GYTopBar setTitleRightDrawable(int resId) {
        return setTitleRightDrawable(getResources().getDrawable(resId));
    }

    public Drawable getTitleRightDrawable() {
        return titleRightDrawable;
    }

    public GYTopBar setTitleRightDrawableWidthDp(int titleRightDrawableWidthDp) {
        return setTitleRightDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), titleRightDrawableWidthDp));
    }

    public GYTopBar setTitleRightDrawableWidthPx(int titleRightDrawableWidthPx) {
        return setTitleRightDrawableSizePx(titleRightDrawableWidthPx, titleRightDrawableHeightPx);
    }

    public GYTopBar setTitleRightDrawableHeightDp(int titleRightDrawableHeightDp) {
        return setTitleRightDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), titleRightDrawableHeightDp));
    }

    public GYTopBar setTitleRightDrawableHeightPx(int titleRightDrawableHeightPx) {
        return setTitleRightDrawableSizePx(titleRightDrawableWidthPx, titleRightDrawableHeightPx);
    }

    public GYTopBar setTitleRightDrawableSizePx(int titleRightDrawableWidthPx, int titleRightDrawableHeightPx) {
        this.titleRightDrawableWidthPx = titleRightDrawableWidthPx;
        this.titleRightDrawableHeightPx = titleRightDrawableHeightPx;
        setImageViewSizePx(titleRightImageView, titleRightDrawable, titleRightDrawableWidthPx, titleRightDrawableHeightPx);
        return this;
    }

    public int getTitleRightDrawableWidthPx() {
        return titleRightDrawableWidthPx;
    }

    public int getTitleRightDrawableHeightPx() {
        return titleRightDrawableHeightPx;
    }

    public GYImageView getTitleRightImageView() {
        return titleRightImageView;
    }

    public GYTopBar setTitleRightImageViewMarginPx(int leftPx, int rightPx) {
        titleRightImageView.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setTitleRightImageViewMarginDp(int leftDp, int rightDp) {
        titleRightImageView.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    //==============================================================================================
    //中间右边文字
    public GYTopBar setRightText(String text) {
        if (TextUtils.isEmpty(text)) {
            rightTextView.setVisibility(GONE);
        } else {
            rightTextView.getViewSet().setVisibility(VISIBLE)
                    .setText(text);
        }
        return this;
    }

    public String getRightTextString() {
        return rightTextView.getViewSet().getTextString();
    }

    public GYTopBar setRightTextSizePx(int sizePx) {
        rightTextSizePx = sizePx;
        rightTextView.getViewSet().setTextSizePx(rightTextSizePx);
        return this;
    }

    public int getRightTextSizePx() {
        return rightTextSizePx;
    }

    public GYTopBar setRightTextSizeSp(int sizeSp) {
        return setRightTextSizePx(GYDisplayUtils.sp2px(getContext(), sizeSp));
    }

    public GYTopBar setRightTextColor(int color) {
        rightTextColor = color;
        rightTextView.getViewSet().setTextColor(rightTextColor);
        return this;
    }

    public int getRightTextColor() {
        return rightTextColor;
    }

    public GYTopBar setRightTextViewMarginPx(int RightPx, int rightPx) {
        rightTextView.getViewSet().setMarginPx(RightPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setRightTextViewMarginDp(int RightDp, int rightDp) {
        rightTextView.getViewSet().setMarginDp(RightDp, 0, rightDp, 0);
        return this;
    }

    public GYTextView getRightTextView() {
        return rightTextView;
    }

    public GYTopBar setRightTextBold(boolean bold) {
        rightTextView.getViewSet().setBold(bold);
        return this;
    }

    public boolean isRightTextBold() {
        return rightTextView.getViewSet().isBold();
    }

    //==============================================================================================
    //中间右边图片
    public GYTopBar setRightDrawable(Drawable rightDrawable) {
        this.rightDrawable = rightDrawable;
        if (rightDrawable == null) {
            rightImageView.setVisibility(GONE);
        } else {
            rightImageView.getViewSet().setVisibility(VISIBLE).toView()
                    .getImageBuilder()
                    .setImageDrawable(rightDrawable).build();
        }
        return this;
    }

    public GYTopBar setRightDrawable(int resId) {
        return setRightDrawable(getResources().getDrawable(resId));
    }

    public Drawable getRightDrawable() {
        return rightDrawable;
    }

    public GYTopBar setRightDrawableWidthDp(int rightDrawableWidthDp) {
        return setRightDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), rightDrawableWidthDp));
    }

    public GYTopBar setRightDrawableWidthPx(int rightDrawableWidthPx) {
        return setRightDrawableSizePx(rightDrawableWidthPx, rightDrawableHeightPx);
    }

    public GYTopBar setRightDrawableHeightDp(int rightDrawableHeightDp) {
        return setRightDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), rightDrawableHeightDp));
    }

    public GYTopBar setRightDrawableHeightPx(int rightDrawableHeightPx) {
        return setRightDrawableSizePx(rightDrawableWidthPx, rightDrawableHeightPx);
    }

    public GYTopBar setRightDrawableSizePx(int rightDrawableWidthPx, int rightDrawableHeightPx) {
        this.rightDrawableWidthPx = rightDrawableWidthPx;
        this.rightDrawableHeightPx = rightDrawableHeightPx;
        setImageViewSizePx(rightImageView, rightDrawable, rightDrawableWidthPx, rightDrawableHeightPx);
        return this;
    }

    public int getRightDrawableWidthPx() {
        return rightDrawableWidthPx;
    }

    public int getRightDrawableHeightPx() {
        return rightDrawableHeightPx;
    }

    public GYImageView getRightImageView() {
        return rightImageView;
    }

    public GYTopBar setRightImageViewMarginPx(int leftPx, int rightPx) {
        rightImageView.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setRightImageViewMarginDp(int leftDp, int rightDp) {
        rightImageView.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    //==============================================================================================
    //中间右边图片1
    public GYTopBar setRightDrawable1(Drawable rightDrawable1) {
        this.rightDrawable1 = rightDrawable1;
        if (rightDrawable1 == null) {
            rightImageView1.setVisibility(GONE);
        } else {
            rightImageView1.getViewSet().setVisibility(VISIBLE)
                    .toView().getImageBuilder()
                    .setImageDrawable(rightDrawable1).build();
        }
        return this;
    }

    public GYTopBar setRightDrawable1(int resId) {
        return setRightDrawable1(getResources().getDrawable(resId));
    }

    public Drawable getRightDrawable1() {
        return rightDrawable1;
    }

    public GYTopBar setRightDrawable1WidthDp(int rightDrawable1WidthDp) {
        return setRightDrawable1WidthPx(GYDisplayUtils.dp2px(getContext(), rightDrawable1WidthDp));
    }

    public GYTopBar setRightDrawable1WidthPx(int rightDrawable1WidthPx) {
        return setRightDrawable1SizePx(rightDrawable1WidthPx, rightDrawable1HeightPx);
    }

    public GYTopBar setRightDrawable1HeightDp(int rightDrawable1HeightDp) {
        return setRightDrawable1HeightPx(GYDisplayUtils.dp2px(getContext(), rightDrawable1HeightDp));
    }

    public GYTopBar setRightDrawable1HeightPx(int rightDrawable1HeightPx) {
        return setRightDrawable1SizePx(rightDrawable1WidthPx, rightDrawable1HeightPx);
    }

    public GYTopBar setRightDrawable1SizePx(int rightDrawable1WidthPx, int rightDrawable1HeightPx) {
        this.rightDrawable1WidthPx = rightDrawable1WidthPx;
        this.rightDrawable1HeightPx = rightDrawable1HeightPx;
        setImageViewSizePx(rightImageView1, rightDrawable1, rightDrawable1WidthPx, rightDrawable1HeightPx);
        return this;
    }

    public int getRightDrawable1WidthPx() {
        return rightDrawable1WidthPx;
    }

    public int getRightDrawable1HeightPx() {
        return rightDrawable1HeightPx;
    }

    public GYImageView getRightImageView1() {
        return rightImageView1;
    }

    public GYTopBar setRightImageView1MarginPx(int leftPx, int rightPx) {
        rightImageView1.getViewSet().setMarginPx(leftPx, 0, rightPx, 0);
        return this;
    }

    public GYTopBar setRightImageView1MarginDp(int leftDp, int rightDp) {
        rightImageView1.getViewSet().setMarginDp(leftDp, 0, rightDp, 0);
        return this;
    }

    //==============================================================================================
    //总
    public GYTopBar setDrawableSizePx(int drawableWidthPx, int drawableHeightPx) {
        setLeftDrawableSizePx(drawableWidthPx, drawableHeightPx);
        setTitleLeftDrawableSizePx(drawableWidthPx, drawableHeightPx);
        setTitleRightDrawableSizePx(drawableWidthPx, drawableHeightPx);
        setRightDrawableSizePx(drawableWidthPx, drawableHeightPx);
        setRightDrawable1SizePx(drawableWidthPx, drawableHeightPx);
        return this;
    }

    public GYTopBar setDrawableSizeDp(int drawableWidthDp, int drawableHeightDp) {
        return setDrawableSizePx(GYDisplayUtils.dp2px(getContext(), drawableWidthDp), GYDisplayUtils.dp2px(getContext(), drawableHeightDp));
    }

//    public GYTopBar setDrawableWidthPx(int drawableWidthPx) {
//        return this;
//    }
//
//    public GYTopBar setDrawableWidthDp(int drawableWidthDp) {
//        return setDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), drawableWidthDp));
//    }
//
//    public GYTopBar setDrawableHeightPx(int drawableHeightPx) {
//        return this;
//    }
//
//    public GYTopBar setDrawableHeightDp(int drawableHeightDp) {
//        return setDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), drawableHeightDp));
//    }

    public GYTopBar setTextSizePx(int textSizePx) {
        setLeftTextSizePx(textSizePx);
        setTitleTextSizePx(textSizePx);
        setRightTextSizePx(textSizePx);
        return this;
    }

    public GYTopBar setTextSizeSp(int textSizeSp) {
        return setTextSizePx(GYDisplayUtils.sp2px(getContext(), textSizeSp));
    }

    public GYTopBar setTextColor(int textColor) {
        setLeftTextColor(textColor);
        setTitleTextColor(textColor);
        setRightTextColor(textColor);
        return this;
    }

    public GYTopBar setSpacingPx(int spacingPx) {
        setLeftSpacingPx(spacingPx);
        setTitleLeftSpacingPx(spacingPx);
        setTitleRightSpacingPx(spacingPx);
        setRightSpacingPx(spacingPx);
        setRightSpacing1Px(spacingPx);
        return this;
    }

    public GYTopBar setSpacingDp(int spacingDp) {
        return setSpacingPx(GYDisplayUtils.dp2px(getContext(), spacingDp));
    }

    public GYTopBar setPaddingPx(int paddingPx) {
        setLeftPaddingLeftPx(paddingPx);
        setRightPaddingRightPx(paddingPx);
        return this;
    }

    public GYTopBar setPaddingDp(int paddingDp) {
        return setPaddingPx(GYDisplayUtils.dp2px(getContext(), paddingDp));
    }

    public GYTopBar setTextBold(boolean bold) {
        setLeftTextBold(bold);
        setTitleTextBold(bold);
        setRightTextBold(bold);
        return this;
    }

    //===============================================================================================
    public GYTopBar(Context context) {
        this(context, null);
    }

    public GYTopBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    @SuppressLint("NewApi")
    public GYTopBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public GYTopBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(attrs);
    }

    private GYLinearLayout leftLL, rightLL, titleLL;
    private GYRelativeLayout centerView;
    private GYImageView leftImageView, titleLeftImageView, titleRightImageView, rightImageView, rightImageView1;
    private GYTextView leftTextView, titleTextView, rightTextView;
    private View topView, bottomLineView;

    //顶部
    private int topBackgroundColor = Color.TRANSPARENT;
    private boolean topShow = false;
    private int topHeightPx = WRAP_CONTENT;

    //内容
    private int centerBackgroundColor = WRAP_CONTENT;
    private int centerHeightPx = WRAP_CONTENT;

    private int textSizePx = GYDisplayUtils.sp2px(getContext(), 14);
    private int textColor = Color.BLACK;
    private int drawableWidthPx = WRAP_CONTENT;
    private int drawableHeightPx = WRAP_CONTENT;
    private int leftPaddingLeftPx = 0;
    private int rightPaddingRightPx = 0;
    private int leftSpacingPx = 0;
    private int titleLeftSpacingPx = 0;
    private int titleRightSpacingPx = 0;
    private int rightSpacingPx = 0;
    private int rightSpacing1Px = 0;

    //内容左边图片
    private Drawable leftDrawable;
    private int leftDrawableWidthPx = WRAP_CONTENT;
    private int leftDrawableHeightPx = WRAP_CONTENT;
    private int leftTextSizePx = WRAP_CONTENT;
    private int leftTextColor = WRAP_CONTENT;
    private boolean leftTextBold = false;

    //内容标题左边图片
    private Drawable titleLeftDrawable;
    private int titleLeftDrawableWidthPx = WRAP_CONTENT;
    private int titleLeftDrawableHeightPx = WRAP_CONTENT;

    //内容标题文字
    private int titleTextSizePx = WRAP_CONTENT;
    private int titleTextColor = WRAP_CONTENT;

    //内容标题右边图片
    private Drawable titleRightDrawable;
    private int titleRightDrawableWidthPx = WRAP_CONTENT;
    private int titleRightDrawableHeightPx = WRAP_CONTENT;
    private boolean titleTextBold = false;

    //内容右边文字
    private int rightTextSizePx = WRAP_CONTENT;
    private int rightTextColor = WRAP_CONTENT;

    //内容右边图片
    private Drawable rightDrawable;
    private int rightDrawableWidthPx = WRAP_CONTENT;
    private int rightDrawableHeightPx = WRAP_CONTENT;

    //内容右边图片1
    private Drawable rightDrawable1;
    private int rightDrawable1WidthPx = WRAP_CONTENT;
    private int rightDrawable1HeightPx = WRAP_CONTENT;

    private boolean rightTextBold = false;

    private boolean bottomLineShow = false;
    private int bottomLineHeightPx = 1;
    private int bottomLineColor = Color.GRAY;

    private boolean textBold = false;
    private int paddingPx = WRAP_CONTENT;
    private int spacingPx = WRAP_CONTENT;

    public void init(AttributeSet attributeSet) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.view_gy_top_bar, this);
        topView = view.findViewById(R.id.topView);
        centerView = view.findViewById(R.id.centerView);
        leftLL = view.findViewById(R.id.ll_left);
        titleLL = view.findViewById(R.id.ll_title);
        rightLL = view.findViewById(R.id.ll_right);
        bottomLineView = view.findViewById(R.id.bottomLineView);
        leftImageView = GYImageView.newInstance(getContext());
        leftTextView = GYTextView.newInstance(getContext());
        titleLeftImageView = GYImageView.newInstance(getContext());
        titleTextView = GYTextView.newInstance(getContext());
        titleRightImageView = GYImageView.newInstance(getContext());
        rightTextView = GYTextView.newInstance(getContext());
        rightImageView = GYImageView.newInstance(getContext());
        rightImageView1 = GYImageView.newInstance(getContext());
        leftLL.getViewSet().addViews(leftImageView, leftTextView);
        titleLL.getViewSet().addViews(titleLeftImageView, titleTextView, titleRightImageView);
        rightLL.getViewSet().addViews(rightImageView1, rightImageView, rightTextView);
        if (attributeSet != null) {
            TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.GYTopBar);
            topBackgroundColor = typedArray.getColor(R.styleable.GYTopBar_topBackgroundColor, topBackgroundColor);
            centerBackgroundColor = typedArray.getColor(R.styleable.GYTopBar_centerBackgroundColor, centerBackgroundColor);
            centerHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_centerHeight, centerHeightPx);
            topShow = typedArray.getBoolean(R.styleable.GYTopBar_topShow, topShow);
            topHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_topHeight, topHeightPx);
            textSizePx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_textSize, textSizePx);
            textColor = typedArray.getColor(R.styleable.GYTopBar_textColor, textColor);
            drawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_drawableWidth, drawableWidthPx);
            drawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_drawableHeight, drawableHeightPx);
            leftDrawable = typedArray.getDrawable(R.styleable.GYTopBar_leftDrawable);
            leftDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_leftDrawableWidth, leftDrawableWidthPx);
            leftDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_leftDrawableHeight, leftDrawableHeightPx);
            String leftText = typedArray.getString(R.styleable.GYTopBar_leftText);
            setLeftText(leftText);
            leftTextSizePx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_leftTextSize, leftTextSizePx);
            leftTextColor = typedArray.getColor(R.styleable.GYTopBar_leftTextColor, leftTextColor);
            leftPaddingLeftPx = typedArray.getDimensionPixelOffset(R.styleable.GYTopBar_leftPaddingLeft, leftPaddingLeftPx);
            leftSpacingPx = typedArray.getDimensionPixelOffset(R.styleable.GYTopBar_leftSpacing, leftSpacingPx);
            leftTextBold = typedArray.getBoolean(R.styleable.GYTopBar_leftTextBold, leftTextBold);
            textBold = typedArray.getBoolean(R.styleable.GYTopBar_textBold, textBold);
            titleLeftDrawable = typedArray.getDrawable(R.styleable.GYTopBar_titleLeftDrawable);
            titleLeftDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleLeftDrawableWidth, titleLeftDrawableWidthPx);
            titleLeftDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleLeftDrawableHeight, titleLeftDrawableHeightPx);
            String titleText = typedArray.getString(R.styleable.GYTopBar_titleText);
            setTitleText(titleText);
            titleTextSizePx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleTextSize, titleTextSizePx);
            titleTextColor = typedArray.getColor(R.styleable.GYTopBar_titleTextColor, titleTextColor);
            titleRightDrawable = typedArray.getDrawable(R.styleable.GYTopBar_titleRightDrawable);
            titleRightDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleRightDrawableWidth, titleRightDrawableWidthPx);
            titleRightDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleRightDrawableHeight, titleRightDrawableHeightPx);
            titleLeftSpacingPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleLeftSpacing, titleLeftSpacingPx);
            titleRightSpacingPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_titleRightSpacing, titleRightSpacingPx);
            titleTextBold = typedArray.getBoolean(R.styleable.GYTopBar_titleTextBold, titleTextBold);
            rightDrawable = typedArray.getDrawable(R.styleable.GYTopBar_rightDrawable);
            rightDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightDrawableWidth, rightDrawableWidthPx);
            rightDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightDrawableHeight, rightDrawableHeightPx);
            rightDrawable1 = typedArray.getDrawable(R.styleable.GYTopBar_rightDrawable1);
            rightDrawable1WidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightDrawable1Width, rightDrawable1WidthPx);
            rightDrawable1HeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightDrawable1Height, rightDrawable1HeightPx);
            String rightText = typedArray.getString(R.styleable.GYTopBar_rightText);
            setRightText(rightText);
            rightTextSizePx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightTextSize, rightTextSizePx);
            rightTextColor = typedArray.getColor(R.styleable.GYTopBar_rightTextColor, rightTextColor);
            rightSpacingPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightSpacing, rightSpacingPx);
            rightSpacing1Px = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightSpacing1, rightSpacing1Px);
            rightPaddingRightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_rightPaddingRight, rightPaddingRightPx);
            rightTextBold = typedArray.getBoolean(R.styleable.GYTopBar_rightTextBold, rightTextBold);
            bottomLineShow = typedArray.getBoolean(R.styleable.GYTopBar_bottomLineShow, bottomLineShow);
            bottomLineHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_bottomLineHeight, bottomLineHeightPx);
            bottomLineColor = typedArray.getColor(R.styleable.GYTopBar_bottomLineColor, bottomLineColor);
            paddingPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_padding, paddingPx);
            spacingPx = typedArray.getDimensionPixelSize(R.styleable.GYTopBar_spacing, spacingPx);
            typedArray.recycle();
        }
        init();
    }

    private void init() {
        //总汇
        leftTextSizePx = leftTextSizePx < 0 ? textSizePx : leftTextSizePx;
        titleTextSizePx = titleTextSizePx < 0 ? textSizePx : titleTextSizePx;
        rightTextSizePx = rightTextSizePx < 0 ? textSizePx : rightTextSizePx;
        leftTextColor = leftTextColor == WRAP_CONTENT ? textColor : leftTextColor;
        titleTextColor = titleTextColor == WRAP_CONTENT ? textColor : titleTextColor;
        rightTextColor = rightTextColor == WRAP_CONTENT ? textColor : rightTextColor;
        if (textBold) {
            leftTextBold = true;
            titleTextBold = true;
            rightTextBold = true;
        }
        if (drawableWidthPx != WRAP_CONTENT) {
            leftDrawableWidthPx = drawableWidthPx;
            titleLeftDrawableWidthPx = drawableWidthPx;
            titleRightDrawableWidthPx = drawableWidthPx;
            rightDrawableWidthPx = drawableWidthPx;
            rightDrawable1WidthPx = drawableWidthPx;
        }
        if (drawableHeightPx != WRAP_CONTENT) {
            leftDrawableHeightPx = drawableHeightPx;
            titleLeftDrawableHeightPx = drawableHeightPx;
            titleRightDrawableHeightPx = drawableHeightPx;
            rightDrawableHeightPx = drawableHeightPx;
            rightDrawable1HeightPx = drawableHeightPx;
        }
        if (paddingPx != WRAP_CONTENT) {
            leftPaddingLeftPx = paddingPx;
            rightPaddingRightPx = paddingPx;
        }
        if (spacingPx != WRAP_CONTENT) {
            leftSpacingPx = spacingPx;
            titleLeftSpacingPx = spacingPx;
            titleRightSpacingPx = spacingPx;
            rightSpacingPx = spacingPx;
            rightSpacing1Px = spacingPx;
        }
        //顶部布局
        setTopBackgroundColor(topBackgroundColor);
        setTopShow(topShow);
        setTopHeightPx(topHeightPx);
        //内容布局
        setCenterBackgroundColor(centerBackgroundColor);
        setCenterHeightPx(centerHeightPx);
        //内容左边布局
        setLeftPaddingLeftPx(leftPaddingLeftPx);
        setLeftSpacingPx(leftSpacingPx);
        //内容中间布局
        setTitleLeftSpacingPx(titleLeftSpacingPx);
        setTitleRightSpacingPx(titleRightSpacingPx);
        //内容右边布局
        setRightPaddingRightPx(rightPaddingRightPx);
        setRightSpacingPx(rightSpacingPx);
        setRightSpacing1Px(rightSpacing1Px);
        //内容左边图片
        setLeftDrawable(leftDrawable);
        setLeftDrawableWidthPx(leftDrawableWidthPx);
        setLeftDrawableHeightPx(leftDrawableHeightPx);
        //内容左边文字
        setLeftTextSizePx(leftTextSizePx);
        setLeftTextColor(leftTextColor);
        setLeftTextBold(leftTextBold);
        //内容中间左边图片
        setTitleLeftDrawable(titleLeftDrawable);
        setTitleLeftDrawableWidthPx(titleLeftDrawableWidthPx);
        setTitleLeftDrawableHeightPx(titleLeftDrawableHeightPx);
        //内容中间文字
        setTitleTextSizePx(titleTextSizePx);
        setTitleTextColor(titleTextColor);
        setTitleTextBold(titleTextBold);
        //内容中间右边图片
        setTitleRightDrawable(titleRightDrawable);
        setTitleRightDrawableWidthPx(titleRightDrawableWidthPx);
        setTitleRightDrawableHeightPx(titleRightDrawableHeightPx);
        //内容右边文字
        setRightTextSizePx(rightTextSizePx);
        setRightTextColor(rightTextColor);
        setRightTextBold(rightTextBold);
        //内容右边图片
        setRightDrawable(rightDrawable);
        setRightDrawableWidthPx(rightDrawableWidthPx);
        setRightDrawableHeightPx(rightDrawableHeightPx);
        //内容右边图片1
        setRightDrawable1(rightDrawable1);
        setRightDrawable1WidthPx(rightDrawable1WidthPx);
        setRightDrawable1HeightPx(rightDrawable1HeightPx);
        //底部
        setBottomLineShow(bottomLineShow);
        setBottomLineHeightPx(bottomLineHeightPx);
        setBottomLineColor(bottomLineColor);
    }

    //========================================================================================
    public List<View> getLeftViews() {
        return GYViewUtils.getChildViewList(leftLL);
    }

    public List<View> getTitleViews() {
        return GYViewUtils.getChildViewList(titleLL);
    }

    public List<View> getRightViews() {
        return GYViewUtils.getChildViewList(rightLL);
    }

    public List<View> getViews(int viewPosition) {
        return GYViewUtils.getChildViewList(viewLL(viewPosition));
    }
    //=============================================================================

    public GYTopBar removeLeftAllViews() {
        return removeAllViews(ViewPosition.LEFT);
    }

    public GYTopBar removeTitleAllViews() {
        return removeAllViews(ViewPosition.TITLE);
    }

    public GYTopBar removeRightAllViews() {
        return removeAllViews(ViewPosition.RIGHT);
    }

    public GYTopBar removeAllViews(int viewPosition) {
        viewLL(viewPosition).removeAllViews();
        return this;
    }

    @Override
    public void removeAllViews() {
//        super.removeAllViews();
        leftLL.removeAllViews();
        titleLL.removeAllViews();
        rightLL.removeAllViews();
    }

    //=============================================================================
    public GYTopBar removeLeftViewAt(int index) {
        return removeViewAt(ViewPosition.LEFT, index);
    }

    public GYTopBar removeTitleViewAt(int index) {
        return removeViewAt(ViewPosition.TITLE, index);
    }

    public GYTopBar removeRightViewAt(int index) {
        return removeViewAt(ViewPosition.RIGHT, index);
    }

    public GYTopBar removeViewAt(int viewPosition, int index) {
        viewLL(viewPosition).removeViewAt(index);
        return this;
    }

    //=============================================================================
    private LinearLayout viewLL(int viewPosition) {
        switch (viewPosition) {
            case ViewPosition.LEFT:
                return leftLL;
            case ViewPosition.TITLE:
                return titleLL;
            case ViewPosition.RIGHT:
                return rightLL;
        }
        return new LinearLayout(getContext());
    }

    public GYTopBar setOnTopClickListener(OnClickListener onTopClickListener) {
        topView.setOnClickListener(onTopClickListener);
        return this;
    }

    private GYTopBar setOnLeftClickListener(OnClickListener onLeftClickListener) {
        leftLL.setOnClickListener(onLeftClickListener);
        return this;
    }

    public GYTopBar setOnLeftTextClickListener(OnClickListener onLeftTextClickListener) {
        leftTextView.setOnClickListener(onLeftTextClickListener);
        return this;
    }

    public GYTopBar setOnLeftImageClickListener(OnClickListener onLeftImageClickListener) {
        leftImageView.setOnClickListener(onLeftImageClickListener);
        return this;
    }

    public GYTopBar setOnRightClickListener(OnClickListener onRightClickListener) {
        rightLL.setOnClickListener(onRightClickListener);
        return this;
    }

    public GYTopBar setOnRightTextClickListener(OnClickListener onRightTextClickListener) {
        rightTextView.setOnClickListener(onRightTextClickListener);
        return this;
    }

    public GYTopBar setOnRightImageClickListener(OnClickListener onRightImageClickListener) {
        rightImageView.setOnClickListener(onRightImageClickListener);
        return this;
    }

    public GYTopBar setOnRightImage1ClickListener(OnClickListener onRightImage1ClickListener) {
        rightImageView1.setOnClickListener(onRightImage1ClickListener);
        return this;
    }

    public GYTopBar setOnTitleClickListener(OnClickListener onTitleClickListener) {
        titleLL.setOnClickListener(onTitleClickListener);
        return this;
    }

    public GYTopBar setOnTitleLeftClickListener(OnClickListener onTitleLeftClickListener) {
        titleLeftImageView.setOnClickListener(onTitleLeftClickListener);
        return this;
    }

    public GYTopBar setOnTitleTextClickListener(OnClickListener onTitleTextClickListener) {
        titleTextView.setOnClickListener(onTitleTextClickListener);
        return this;
    }

    public GYTopBar setOnTitleRightClickListener(OnClickListener onTitleRightClickListener) {
        titleRightImageView.setOnClickListener(onTitleRightClickListener);
        return this;
    }

    private int normalInt(int now, int to) {
        return now == WRAP_CONTENT ? to : now;
    }
}
